package com.google.code.hibernate.rest.representation;
import static com.google.code.hibernate.rest.internal.InternalPreconditions.checkNotNull;

import java.util.ArrayList;
import java.util.List;

/**
 * 
 * @author wangzijian
 * 
 */
public class EntityList<E> extends ArrayList<E> {

	private static final String WRAPPER_SUFFIX_OBJECT = "List";
	private static final String WRAPPER_SUFFIX_COLLECTION = "Wrapper";

	private static final long serialVersionUID = 1L;

	private final String entityName;

	private EntityList(String entityName, List<? extends E> collections) {
		super(collections);
		this.entityName = checkNotNull(entityName, "entityName");
	}
	
	public static <E> EntityList<E> create(String entityName, List<? extends E> collections) {	
		return new EntityList<E>(entityName, collections);
	}
	
	public String getEntityName() {
		return entityName;
	}

	public String getWrapperName() {
		String suffix;
		if (entityName.endsWith("List") || entityName.endsWith("Set") || entityName.endsWith("Collection")) {
			suffix = WRAPPER_SUFFIX_COLLECTION;
		} else {
			suffix = WRAPPER_SUFFIX_OBJECT;
		}
		return entityName + suffix;
	}
}
